#### Start of system configuration section. ####

srcdir =	@srcdir@
VPATH =		@srcdir@

# Common prefix for machine-independent installed files.
prefix =	@prefix@

# Common prefix for machine-dependent installed files.
exec_prefix =	@exec_prefix@

bindir =	$(exec_prefix)/bin
libdir =	$(exec_prefix)/Sys/libs

INSTALL =	@INSTALL@
INSTALL_DATA =	@INSTALL_DATA@

CC =		@CC@

CFLAGS =	@CFLAGS@
LDFLAGS =	@LDFLAGS@

RANLIB =	@RANLIB@
AR =		ar
RM =		rm -f

#### End system configuration section ####

# For now we only build one CPU/FPU flavor of libc.a, which is the most generic version.

CPUDIR		= 68000
FPUDIR		= soft-float

FLAVOR_CFLAGS =
#OTHER_CFLAGS =	-m68020 -Wa,-m68020,-mno-68881
OTHER_CFLAGS =	-fomit-frame-pointer
ALL_CFLAGS =	$(CFLAGS) $(FLAVOR_CFLAGS) $(OTHER_CFLAGS) $(INCS) $(DEFS)

DEFS =
INCS =		-I$(srcdir) -I$(srcdir)/../library -I$(srcdir)/../include
LIB =		libstdio.a
SHELL =		/bin/sh

.c.o:
		$(CC) $(ALL_CFLAGS) -c $< -o $@

.s.o:
		cp $*.s x.c
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) -traditional -E x.c -o x.s
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -c x.s -o $*.o
		$(RM) x.c x.s


SRCS =		__panic.c crt0.c v1.c v2.c v3.c v4.c v5.c v6.c v7.c v8.c v9.c v10.c

OBJS =		__panic.o v1.o v2.o v3.o v4.o v5.o v6.o v7.o v8.o v9.o v10.o

all:		libcrt.a libc.a libbc.a crt0.o bcrt0.o rcrt0.o # gcrt0.o

crt0.o:		crt0.c $(srcdir)/../library/version.h
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -c -DCRT0 $(srcdir)/crt0.c

bcrt0.o:	crt0.c $(srcdir)/../library/version.h
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) -fbaserel -DBASECRT0 $(INCS) -c $(srcdir)/crt0.c -o bcrt0.o

rcrt0.o:	crt0.c $(srcdir)/../library/version.h
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) -fbaserel -DBASECRT0 -DRCRT0 $(INCS) -c $(srcdir)/crt0.c -o rcrt0.o

#moncrt0.o:	crt0.c $(srcdir)/../library/version.h
#		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -c -DMCRT0 $(srcdir)/crt0.c -o moncrt0.o
#		ld -x -r moncrt0.o
#		mv a.out moncrt0.o

#gcrt0.o:	moncrt0.o gmon.o
#		ld -x -r -o gcrt0.o moncrt0.o gmon.o

#gmon.o:		gmon.c gmon.h
#		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -c -fno-omit-frame-pointer $(srcdir)/gmon.c -o gmon.o
#		ld -x -r gmon.o
#		mv a.out gmon.o


libcrt.a:	$(OBJS)
		$(RM) libcrt.a
		$(AR) qc libcrt.a $(OBJS)

libc.a:		libcrt.a ../glue/no-baserel/libglue.a ../static/no-baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a \
		../stack/no-baserel/$(CPUDIR)/$(FPUDIR)/libstack.a ../network/no-baserel/$(CPUDIR)/$(FPUDIR)/libnet.a
		$(RM) $@
		$(RM) -r tempobj
		mkdir tempobj
		(cd tempobj; $(AR) x ../libcrt.a)
		(cd tempobj; $(AR) x ../../glue/no-baserel/libglue.a)
		(cd tempobj; $(AR) x ../../static/no-baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a)
		(cd tempobj; $(AR) x ../../stack/no-baserel/$(CPUDIR)/$(FPUDIR)/libstack.a)
#		(cd tempobj; $(AR) x ../../network/no-baserel/$(CPUDIR)/$(FPUDIR)/libnet.a)
		(cd tempobj; $(AR) rv ../$@ *.o)
		$(RANLIB) $@
		$(RM) -r tempobj

libbc.a:	libcrt.a ../glue/baserel/libglue.a ../static/baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a \
		../stack/baserel/$(CPUDIR)/$(FPUDIR)/libstack.a ../network/baserel/$(CPUDIR)/$(FPUDIR)/libnet.a
		$(RM) $@
		$(RM) -r tempobj
		mkdir tempobj
		(cd tempobj; $(AR) x ../libcrt.a)
		(cd tempobj; $(AR) x ../../glue/baserel/libglue.a)
		(cd tempobj; $(AR) x ../../static/baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a)
		(cd tempobj; $(AR) x ../../stack/baserel/$(CPUDIR)/$(FPUDIR)/libstack.a)
#		(cd tempobj; $(AR) x ../../network/baserel/$(CPUDIR)/$(FPUDIR)/libnet.a)
		(cd tempobj; $(AR) rv ../$@ *.o)
		$(RANLIB) $@
		$(RM) -r tempobj
